package com.qumitech.visualnovel.controller.rest;


import com.qumitech.visualnovel.model.common.BaseRsp;
import com.qumitech.visualnovel.model.common.ResultEnum;
import com.qumitech.visualnovel.controller.vo.applePay.ApplePayVO;
import com.qumitech.visualnovel.service.applepay.ApplePayService;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/api/applePay")
public class ApplePayController {
    @Autowired
    ApplePayService applePayService;

    @RequiresPermissions("applePay:add")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public BaseRsp save(@RequestBody ApplePayVO applePayVO)
    {
        applePayService.saveApplePay(applePayVO);
        return new BaseRsp(ResultEnum.SUCCESS);
    }

    @RequiresPermissions("applePay:view")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public BaseRsp getPayShieldList(@RequestParam(value="payment_name", required=false) String paymentName,
                                       @RequestParam(value="offset", required=false, defaultValue="0") Integer offset,
                                       @RequestParam(value="limit", required=false, defaultValue="20") Integer limit)
    {
        return new BaseRsp(ResultEnum.SUCCESS,applePayService.getApplePayList(paymentName, offset, limit));
    }


    @RequiresPermissions("applePay:change")
    @RequestMapping(value = "/{payment_id}", method = RequestMethod.PUT)
    public BaseRsp getApplyPayUpdate(@RequestBody ApplePayVO applePayVO,
                                     @PathVariable(name = "payment_id") String paymentId) {

        applePayService.updateApplePay(applePayVO, paymentId);
        return new BaseRsp(ResultEnum.SUCCESS);
    }

    @RequiresPermissions("applePay:del")
    @DeleteMapping(value = "/{payment_id}")
    public BaseRsp getApplyPayDelete(@PathVariable(name = "payment_id") String paymentId) {
        applePayService.removeApplyPay(paymentId);
        return new BaseRsp(ResultEnum.SUCCESS);
    }
}
